package com.ymatou.iapi.productcategory.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.ymatou.iapi.productcategory.parameter.BrandDto;
import com.ymatou.iapi.productcategory.service.GetCategoryTagInfoCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.database.mongo.BuyerProductWapper;
import com.ymttest.utils.DiffUtil;
import com.ymttest.utils.EnvSetup;
/**
*FreeMaker Template自动生成代码
*/
import com.ymttest.utils.Logger2Debug;
import com.ymttest.utils.TestDataManager;

@TestSuite
public class Ts_GetCategoryTagInfo {
	private static GetCategoryTagInfoCall GetCategoryTagInfoCall;
	static Logger2Debug Logger = new Logger2Debug();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取所有的品牌信息");
	}

	@Before
	public void caseUp() {
		// 旧站点
//		GetCategoryTagInfoCall = new GetCategoryTagInfoCall(EnvSetup.getSystemUrl("productcategory_api"));
		//新站点
		GetCategoryTagInfoCall = new GetCategoryTagInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(GetCategoryTagInfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	//全部数据 手动执行
	public void Tc_GetCategoryTagInfo_001() {
		Logger.start(true, "获取所有的品牌Tag信息");
		try {
			List<Integer> brandIdList = new ArrayList<Integer>();
			GetCategoryTagInfoCall.callService();
			Logger.verifyEquals("200", GetCategoryTagInfoCall.getString("Code"), "验证Code");
			Logger.debug(FormatUtil.beanToGSONString( GetCategoryTagInfoCall.getCategoryTagInfoList()));
			IntergratedProductMapper ipm = SqlMapperFactory
					.getIntergratedProductMapper();
			List<Map<String, Object>> list = ipm.selectAllTagInfo();
			GetCategoryTagInfoCall.getCategoryTagInfoList().forEach(returnx->{
				returnx.getTagInfoList().forEach(returny->{
					 Map<String, Object> db = list.stream().filter(dbx->{
						return dbx.get("CategoryId").toString().equals(returnx.getCategoryId().toString())&&dbx.get("TagId").toString().equals(returny.getTagId().toString());
						}).findFirst().get();
					 Logger.verifyEquals(db.get("TagValue"), returny.getTagValue(), "TagValue");
					 Logger.verifyEquals(db.get("Name"), returny.getName(), "Name");
					 Logger.verifyEquals(db.get("ChooseType"), returny.getChooseType(), "ChooseType");
				});
				
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}